var VM = new Vue({
    el:'#dicapp',
    data:{
        totalNum:'',
        newsLists:[],
        allChoseFlag:false,
        delMultiFlag:false,
        keyWord:''
    },
    created:function(){
        this.lay();
    },
    methods:{
        lay:function(){
            var _this = this;
            layui.use(['laydate','element','laypage','layer','form'], function(){
                var form = layui.form();
                $ = layui.jquery;//jquery
                laydate = layui.laydate;//日期插件
                lement = layui.element();//面包导航
                laypage = layui.laypage;//分页
                layer = layui.layer;//弹出层
//////////
                //以上模块根据需要引入
                getPageData(1);
                /*请求后台数据，分页请求*/
                function getPageData(curr) {

                    $.ajax({
                        url:"../../StatisticsWeb/getQsDictHospitalList.do?pagenum="+curr+"&pagesize="+5+"&search="+_this.keyWord,
                        dataType:"json",
                        type:"POST",
                        async:false,
                        success:function (res) {
                            //alert("9999")
                            console.log(res);
                            if(res.msg=="success"){
                                var list = res.result.dictHospitalList;
                                _this.newsLists = list;
                                laypage.pages = res.result.total;
                                _this.totalNum = res.result.total;
                                //当只有一页时
                                if(res.result.total > 5){
                                    $(".pageShowFlag").css({"display":"none"});
                                    $(".pageHideFlag").css({"display":"block"});
                                }else if(res.result.total > 0 ){
                                    $(".pageShowFlag").css({"display":"block"});
                                    $(".pageHideFlag").css({"display":"none"});
                                }else{
                                    $(".pageShowFlag").css({"display":"none"});
                                    $(".pageHideFlag").css({"display":"none"});
                                    layer.msg("没有查询到数据！", {icon: 1});
                                }


                                laypage({
                                    cont: 'pagination', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                                    pages: Math.ceil(res.result.total/5), //通过后台拿到的总页数
                                    curr: curr || 1, //当前页
                                    jump: function(obj, first){ //触发分页后的回调
                                        if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                            getPageData(obj.curr);
                                        }
                                    }
                                });
                            }else{
                                layer.msg("没有查询到数据！", {icon: 1})
                            }
                        },
                        error:function (XMLHttpRequest) {
                            layer.msg("系统错误", {icon: 1});
                        }
                    })
                }
                var start = {
                    min: laydate.now()
                    ,max: '2099-06-16 23:59:59'
                    ,istoday: false
                    ,choose: function(datas){
                        end.min = datas; //开始日选好后，重置结束日的最小日期
                        end.start = datas //将结束日的初始值设定为开始日
                    }
                };

                var end = {
                    min: laydate.now()
                    ,max: '2099-06-16 23:59:59'
                    ,istoday: false
                    ,choose: function(datas){
                        start.max = datas; //结束日选好后，重置开始日的最大日期
                    }
                };
                /*全选checked*/
                $("#allChecked").click(function () {
                    if ($(this).is(':checked')) {
                        $("input:checkbox").prop('checked', true)
                    } else {
                        $("input:checkbox").prop('checked', false)
                    }
                });
            });
        },
        allChose:function(){
            var _this = this;
            this.allChoseFlag = !this.allChoseFlag;
            this.newsLists.forEach(function(item,index){
                if(typeof item.checked == "undefined"){
                    Vue.set(item,"checked",true);
                }else{
                    item.checked = _this.allChoseFlag;
                }
            });
        },
        selectSelf:function(item){
            if(typeof item.checked == "undefined"){
                Vue.set(item,"checked",true);
            }else{
                item.checked = !item.checked;
            }
        },
        admin_edits:function(itemId){
            admin_edit("编辑","../../StatisticsWeb/editQsDictHospital.do?id="+ itemId,itemId,'800','500')
        },
        admin_add1:function(){
            admin_add("新增","../../StatisticsWeb/addQsDictHospital.do",'800','500')
        },
        admin_del:function(itemId){
            admin_del("删除","../../QsContent/delete.do?id="+ itemId,'800','500')
        },
        admin_rePsd:function(itemId){},
        check:function () {
        },
        delMulti:function(){},
    }
});

$('button.add').on("click",function(){

    layer.open({
        type: 2,
        title: '添加',
        maxmin: true,
        shadeClose: true, //点击遮罩关闭层
        area : ['800px' , '600px'],
        content: 'edit.html'
    })

});

